from sklearn.linear_model import LinearRegression
from select_database import query_database
import numpy as np
import matplotlib.pyplot as plt #画图的库

def get_history_data():
    query = "select price from 历史价格 order by id desc  limit 1,20"
    df = query_database(query)
    return df

# 预测变量
y = get_history_data()["price"].tolist()
y = [ float(i) for i in y]

# 输出变量
x = [ i for i in range(1,len(y)+1) ]
x = np.array(x).reshape((-1, 1))

model = LinearRegression()

model.fit(x, y)
model = LinearRegression().fit(x, y)

y_pred = list(model.predict(x))

print(y_pred)